#############################################################################################
## Replication code for:                                                                   ##
## A Male Hostility Spiral? Polarized Communication among Political Elites on Social Media ##
## Step 6.                                                                                 ##
#############################################################################################

library(stargazer)
library(reshape2)
library(tidyverse)
library(marginaleffects)
library(readxl)
library(patchwork)
library(dsl)
options(scipen=999)
set.seed(42)

# Load and prepare main data.

data <- read.csv("data1.csv")

data$predicted_sentiment <- recode(data$predicted_sentiment,
                                   "Negative" = -1,
                                   "Neutral" = 0,
                                   "Positive" = 1)

data$predicted_targeted_sentiment <- recode(data$predicted_targeted_sentiment,
                                            "Negative" = -1,
                                            "Neutral" = 0,
                                            "Positive" = 1)

data$inparty <- as.numeric(data$party_id_sender==data$party_id_receiver)

data$country_id <- factor(data$country_id)
data$party_id_sender <- factor(data$party_id_sender)
data$party_id_receiver <- factor(data$party_id_receiver)
data$sender_gender <- as.factor(data$sender_gender)
data$receiver_gender <- as.factor(data$receiver_gender)

# Main regression results

m1 <- lm(predicted_targeted_sentiment~inparty,
          data=data)

m2 <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender,
         data=data)

m3 <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+party_id_receiver+party_id_sender+monthyear,
         data=data)

m4 <- lm(predicted_sentiment~inparty,
          data=data)

m5 <- lm(predicted_sentiment~inparty*sender_gender*receiver_gender,
         data=data)

m6 <- lm(predicted_sentiment~inparty*sender_gender*receiver_gender+monthyear+party_id_receiver+party_id_sender,
         data=data)

stargazer(m1,m2,m3,m4,m5,m6,
          omit = c("party_id_sender", "monthyear","party_id_receiver"),
          keep.stat = c("n", "rsq", "adj.rsq"),
          star.cutoffs = c(0.05, 0.01, 0.001),type="html",report="vc*",
          out="tables_and_figures/tbl4.html")

predicted_effects2 <- avg_predictions(m2,by=c("sender_gender","receiver_gender","inparty"))
predicted_effects2$group <- paste0(predicted_effects2$sender_gender, " to ",predicted_effects2$receiver_gender)
predicted_effects2$Inparty <- factor(predicted_effects2$inparty)
levels(predicted_effects2$Inparty) <- c("Outparty","Inparty")

# Main results visualized

png(file="tables_and_figures/fg4.png",
width=12, height=8, units="cm", res=600)
ggplot(predicted_effects2, aes(x=group,y = estimate,col=Inparty)) +
  geom_point(size=1)+
  geom_errorbar(aes(ymin=conf.low,ymax=conf.high),width=0.2)+
  theme_bw()+
  xlab("")+
  ylab("Predicted Sentiment")+
  theme(legend.position="bottom")+
  labs(color = "")
dev.off()

# Heterogeneity

fix_plot_data <- function(model,name){
  predicted_effects <- marginaleffects::avg_predictions(model,by=c("sender_gender","receiver_gender","inparty"))
  predicted_effects$group <- paste0(predicted_effects$sender_gender, " to ",predicted_effects$receiver_gender)
  predicted_effects$Inparty <- factor(predicted_effects$inparty)
  levels(predicted_effects$Inparty) <- c("Outparty","Inparty")
  
  predicted_effects$name <- name
  return(predicted_effects)
}

countries <- read.csv("countries_data.csv")
countries <- countries %>%
  mutate(
    region = case_when(
      country %in% c("United States", "Canada") ~ "North America",
      country %in% c("Australia", "New Zealand") ~ "Oceania",
      country %in% c("Austria", "Belgium", "France", "Germany", "Netherlands", "Switzerland", "United Kingdom", "Ireland","Luxembourg") ~ "Western Europe",
      country %in% c("Denmark", "Finland", "Norway", "Sweden") ~ "Scandinavia",
      country %in% c("Latvia", "Poland", "Slovenia") ~ "Eastern Europe",
      country %in% c("Italy", "Greece", "Spain","Malta") ~ "Southern Europe",
      TRUE ~ "Other"
    )
  )

data <- merge(data,countries[,c(1,3,4,5)],by="country_id",all.x=T)
data$region <- factor(data$region)
data$electoral_system_family <- factor(data$electoral_system_family)
data$sender_parfam <- factor(data$sender_parfam,levels=c("Socialist","Social Democratic","Ecological",
                                                         "Agrarian","Liberal","Conservative","Christian Democratic","Nationalist"))
# Party system heterogeneity

parsys_data <- NA
for (parsys in levels(data$electoral_system_family)){
  model <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+party_id_sender+party_id_receiver,
              data=data[data$electoral_system_family==parsys,])
  parsys_data <- rbind(parsys_data,fix_plot_data(model,parsys))
  
}
parsys_data <- parsys_data[-1,]
png(file="tables_and_figures/fg9_oa.png",
    width=14, height=12, units="cm", res=600)
ggplot(parsys_data, aes(x=group,y = estimate,col=Inparty)) +
  geom_point(size=1)+
  geom_errorbar(aes(ymin=conf.low,ymax=conf.high),width=0.2)+
  theme_bw()+
  xlab("")+
  ylab("Predicted Sentiment")+
  theme(legend.position="bottom")+
  labs(color = "")+
  facet_wrap(~name)+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
dev.off()


# Geographical region heterogeneity

reg_data <- NA
for (reg in levels(data$region)){
  model <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+party_id_sender+party_id_receiver,
              data=data[data$region==reg,])
  reg_data <- rbind(reg_data,fix_plot_data(model,reg))
  
}
reg_data <- reg_data[-1,]

png(file="tables_and_figures/fg8_oa.png",
    width=14, height=16, units="cm", res=600)
ggplot(reg_data, aes(x=group,y = estimate,col=Inparty)) +
  geom_point(size=1)+
  geom_errorbar(aes(ymin=conf.low,ymax=conf.high),width=0.2)+
  theme_bw()+
  xlab("")+
  ylab("Predicted Sentiment")+
  theme(legend.position="bottom")+
  labs(color = "")+
  facet_wrap(~name)+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
dev.off()

# Party family heterogeneity

parfam_data <- NA
for (parfam in levels(data$sender_parfam)){
  model <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender,
              data=data[data$sender_parfam==parfam,])
  parfam_data <- rbind(parfam_data,fix_plot_data(model,parfam))
  
}
parfam_data <- parfam_data[-1,]

png(file="tables_and_figures/fg10_oa.png",
width=14, height=14, units="cm", res=600)
ggplot(parfam_data, aes(x=group,y = estimate,col=Inparty)) +
  geom_point(size=1)+
  geom_errorbar(aes(ymin=conf.low,ymax=conf.high),width=0.2)+
  theme_bw()+
  xlab("")+
  ylab("Predicted Sentiment")+
  theme(legend.position="bottom")+
  labs(color = "")+
  facet_wrap(~name,nrow=2)+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
dev.off()

# Female representation heterogeneity

women_model1 <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender*prop_parl,
                   data=data)

women_model1_preds <- avg_predictions(women_model1,by=c("sender_gender","receiver_gender","inparty","prop_parl"),
                                      newdata=expand.grid(
                                        sender_gender = c("male", "female"),
                                        receiver_gender = c("male", "female"),
                                        inparty = c(0, 1),
                                        prop_parl = c(0.1, 0.3, 0.5)))

women_model1_preds$group <- paste0(women_model1_preds$sender_gender, " to ",women_model1_preds$receiver_gender)
women_model1_preds$Inparty <- factor(women_model1_preds$inparty)
levels(women_model1_preds$Inparty) <- c("Outparty","Inparty")

women_model1_effects <- avg_slopes(
  model = women_model1,
  variables = "inparty",
  by = c("sender_gender", "receiver_gender", "prop_parl"),
  newdata=expand.grid(
    sender_gender = c("male", "female"),
    receiver_gender = c("male", "female"),
    inparty = c(0, 1),
    prop_parl = c(0.1, 0.3, 0.5)
  )) %>% data.frame()

women_model1_effects$group <- paste0(women_model1_effects$sender_gender, " to ",women_model1_effects$receiver_gender)

p1 <- ggplot(women_model1_effects, aes(x=group,y = estimate)) +
  geom_point(size=1)+
  geom_errorbar(aes(ymin=conf.low,ymax=conf.high),width=0.2)+
  theme_bw()+
  xlab("")+
  ylab("Effect of Inparty")+
  theme(legend.position="bottom")+
  labs(color = "")+
  facet_wrap(~prop_parl)+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

p2 <- ggplot(women_model1_preds, aes(x=group,y = estimate,col=Inparty)) +
  geom_point(size=1)+
  geom_errorbar(aes(ymin=conf.low,ymax=conf.high),width=0.2)+
  theme_bw()+
  xlab("")+
  ylab("Predicted Sentiment")+
  theme(legend.position="top")+
  labs(color = "")+
  facet_wrap(~prop_parl)+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

png(file="tables_and_figures/fg11_oa.png",
width=12, height=16, units="cm", res=600)
print(p2 / p1)
dev.off()

# Robustness checks

# Bootstrap politician sample

bootstrap_model <- function(data, n_boot = 1000) {
  results <- data.frame(inparty = numeric(),
                        inparty_sender_male = numeric(),
                        inparty_receiver_male = numeric(),
                        stringsAsFactors = FALSE)
  
  senders <- unique(data$Sender_id)
  receivers <- unique(data$Receiver_id)
  
  for (i in 1:n_boot) {
    sampled_senders <- sample(senders, length(senders), replace = TRUE)
    
    sampled_data <- data %>%
      filter(Sender_id %in% sampled_senders)
    
    model <- lm(predicted_targeted_sentiment ~ inparty * sender_gender * receiver_gender,
                data = sampled_data)
    
    coefs <- coef(model)
    results <- rbind(results, data.frame(
      inparty = coefs["inparty"],
      inparty_sender_male = coefs["inparty:sender_gendermale"],
      inparty_receiver_male = coefs["inparty:receiver_gendermale"]
    ))
  }
  
  return(results)
}
boot_results <- bootstrap_model(data, n_boot = 100)
boot_results <- melt(boot_results)

png(file="tables_and_figures/fg12_oa.png",
    width=14, height=6, units="cm", res=600)
ggplot(boot_results,aes(x=value))+
  geom_histogram()+
  facet_wrap(~variable,scales="free")+
  theme_bw()+
  xlab("coef. value")
dev.off()

# Removing influential observations

cooks_dist <- cooks.distance(m2)
threshold <- 4 / nrow(data)
influential_obs <- which(cooks_dist > threshold)
m2_cooks <- lm(predicted_targeted_sentiment ~ inparty * sender_gender * receiver_gender, data = data[-influential_obs, ])
cooks_dist <- cooks.distance(m3)
threshold <- 4 / nrow(data)
influential_obs <- which(cooks_dist > threshold)
m3_cooks <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+party_id_receiver+party_id_sender+monthyear,
               data = data[-influential_obs, ])
cooks_dist <- cooks.distance(m5)
threshold <- 4 / nrow(data)
influential_obs <- which(cooks_dist > threshold)
m5_cooks <- lm(predicted_sentiment~inparty*sender_gender*receiver_gender,
               data=data[-influential_obs, ])
cooks_dist <- cooks.distance(m6)
threshold <- 4 / nrow(data)
influential_obs <- which(cooks_dist > threshold)
m6_cooks <- lm(predicted_sentiment~inparty*sender_gender*receiver_gender+party_id_receiver+party_id_sender+monthyear,
               data=data[-influential_obs, ])

stargazer(m2_cooks, m3_cooks,m5_cooks,m6_cooks,
          omit = c("party_id_sender", "monthyear","party_id_receiver"),
          keep.stat = c("n", "rsq", "adj.rsq"),
          star.cutoffs = c(0.05, 0.01, 0.001),type="html",report="vc*",
          out="tables_and_figures/tbl8_oa.html")

# Role of Government participation

gov_model1 <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+
                   sender_ingov+
                   receiver_ingov,
                 data=data)

gov_model2 <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+
                   sender_ingov+
                   receiver_ingov*log(receiver_followers + 1),
                 data=data) # NOTE: Requires "receiver_followers"

gov_model3 <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+
                   receiver_hog*inparty,
                 data=data)

gov_model4 <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+
                   receiver_cabinet*inparty,
                 data=data)

stargazer(gov_model1, gov_model2,gov_model3,gov_model4,
          omit = c("party_id_sender", "monthyear","party_id_receiver"),
          keep.stat = c("n", "rsq", "adj.rsq"),
          star.cutoffs = c(0.05, 0.01, 0.001),type="html",report="vc*",
          out="tables_and_figures/tbl7_oa.html")

# Alternative measure of ingroup

data <- data %>%
  mutate(inparty_pf = if_else(
    is.na(sender_parfam) | is.na(receiver_parfam),
    NA_integer_,
    as.integer(sender_parfam == receiver_parfam)
  ))

data$inparty_govopp  <- ifelse((data$sender_ingov==1&data$receiver_ingov==1)|data$inparty==1,1,0)

m3_pf <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+party_id_sender+party_id_receiver+monthyear,
            data=transform(data,inparty=inparty_pf))

m3_govopp <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+party_id_sender+party_id_receiver+monthyear,
                data=transform(data,inparty=inparty_govopp))

stargazer(m3_pf, m3_govopp,
          omit = c("party_id_sender", "monthyear","party_id_receiver"),
          keep.stat = c("n", "rsq", "adj.rsq"),
          star.cutoffs = c(0.05, 0.01, 0.001),type="html",report="vc*",
          out="tables_and_figures/tbl4.html")

# Country and party family Jackknife models

jacknifes <- function(data,group) {
  results <- data.frame(inparty = numeric(),
                        inparty_sender_male = numeric(),
                        inparty_receiver_male = numeric(),
                        excluded_group = character(),
                        stringsAsFactors = FALSE)
  
  groups <- levels(factor(data[,group]))
  levels(factor(data$group))
  for (i in 1:length(groups)){
    
    model <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender,
                data=data[data[,group]!=groups[i],])
    
    coefs <- coef(model)
    
    results <- rbind(results, data.frame(
      inparty = coefs["inparty"],
      inparty_sender_male = coefs["inparty:sender_gendermale"],
      inparty_receiver_male = coefs["inparty:receiver_gendermale"],
      excluded_group = groups[i]
    ))
  }
  model <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender,
              data=data)
  
  coefs <- coef(model)
  results <- rbind(results, data.frame(
    inparty = coefs["inparty"],
    inparty_sender_male = coefs["inparty:sender_gendermale"],
    inparty_receiver_male = coefs["inparty:receiver_gendermale"],
    excluded_group = "Full"
  ))
  
  return(results)
}

result <- jacknifes(data,"sender_parfam")

result <- result %>%
  pivot_longer(cols = -excluded_group, names_to = "variable", values_to = "coefficient") %>%
  mutate(
    group_type = ifelse(excluded_group == "Full", "Full", "Excluded Group")
  )


png(file="tables_and_figures/fg13_oa.png",
    width=20, height=15, units="cm", res=600)
ggplot(result, aes(x = coefficient, y = excluded_group)) +
  geom_point() +
  facet_grid(group_type ~ variable,scales="free_y",space = "free_y") +
  theme_bw()
dev.off()

# Country jackknife

result <- jacknifes(data,"country")

result <- result %>%
  pivot_longer(cols = -excluded_group, names_to = "variable", values_to = "coefficient") %>%
  mutate(
    group_type = ifelse(excluded_group == "Full", "Full", "Excluded Group")
  )


png(file="tables_and_figures/fg14_oa.png",
    width=20, height=20, units="cm", res=600)
ggplot(result, aes(x = coefficient, y = excluded_group)) +
  geom_point() +
  facet_grid(group_type ~ variable,scales="free_y",space = "free_y") +
  theme_bw()
dev.off()

# Correcting for measurment errors

annotated_data <- read.csv("annotated_data.csv")

annotated_data$predicted_sentiment <- recode(annotated_data$predicted_sentiment,
                                   "Negative" = -1,
                                   "Neutral" = 0,
                                   "Positive" = 1)

annotated_data$predicted_targeted_sentiment <- recode(annotated_data$predicted_targeted_sentiment,
                                            "Negative" = -1,
                                            "Neutral" = 0,
                                            "Positive" = 1)

annotated_data$annotated_sentiment <- recode(annotated_data$annotated_sentiment,
                                   "Negative" = -1,
                                   "Neutral" = 0,
                                   "Positive" = 1)

annotated_data$annotated_targeted_sentiment <- recode(annotated_data$annotated_targeted_sentiment,
                                            "Negative" = -1,
                                            "Neutral" = 0,
                                            "Positive" = 1)

data2 <- data

colnames(annotated_data)[c(6,7)] <- c("predicted_sentiment_oos","predicted_targeted_sentiment_oos")
data2 <- merge(data,annotated_data[c("predicted_sentiment_oos","annotated_sentiment",
                                     "predicted_targeted_sentiment_oos","annotated_targeted_sentiment",
                                     "id_target")],by="id_target",all.x=T)

data2[data2$annotated==1,]$predicted_sentiment <- data2[data2$annotated==1,]$predicted_sentiment_oos
data2[data2$annotated==1,]$predicted_targeted_sentiment <- data2[data2$annotated==1,]$predicted_targeted_sentiment_oos

m1_dsl <- dsl(model = "lm", 
              formula = annotated_targeted_sentiment ~ inparty*sender_gender*receiver_gender,
              predicted_var = "annotated_targeted_sentiment",
              prediction = "predicted_targeted_sentiment",
              data = data2)

print(xtable(summary(m1_dsl),digits=3), type = "html", file = "tables_and_figures/tbl5a_oa.html")

m3_dsl <- dsl(model = "lm", 
              formula = annotated_sentiment ~ inparty*sender_gender*receiver_gender,
              predicted_var = "annotated_sentiment",
              prediction = "predicted_sentiment",
              data = data2)

print(xtable(summary(m3_dsl),digits=3), type = "html", file = "tables_and_figures/tbl5b_oa.html")

# Full name mentions

data_indirect <- read.csv("data2.csv")

data_indirect$predicted_targeted_sentiment <- recode(data_indirect$predicted_targeted_sentiment,
                                                     "Negative" = -1,
                                                     "Neutral" = 0,
                                                     "Positive" = 1)

data_indirect$inparty <- as.numeric(data_indirect$party_id_receiver==data_indirect$party_id_sender)
data_indirect$country_id <- factor(data_indirect$country_id)
data_indirect$party_id_receiver <- factor(data_indirect$party_id_receiver)
data_indirect$party_id_sender <- factor(data_indirect$party_id_sender)
data_indirect$sender_gender <- as.factor(data_indirect$sender_gender)
data_indirect$receiver_gender <- as.factor(data_indirect$receiver_gender)

m2_indirect <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender,
                  data=data_indirect)
m3_indirect <- lm(predicted_targeted_sentiment~inparty*sender_gender*receiver_gender+party_id_sender+party_id_receiver+monthyear,
                  data=data_indirect)

stargazer(m2_indirect, m3_indirect,
          omit = c("party_id_sender", "monthyear","party_id_receiver"),
          keep.stat = c("n", "rsq", "adj.rsq"),
          star.cutoffs = c(0.05, 0.01, 0.001),type="html",report="vc*",
          out="tables_and_figures/tbl6_oa.html")

# Reciprocal communication

avg_sentiment_sender <- data %>%
  group_by(Sender_id) %>%
  summarize(avg_sentiment_sender = mean(predicted_targeted_sentiment, na.rm = TRUE))

avg_sentiment_receiver <- data %>%
  group_by(Receiver_id) %>%
  summarize(avg_sentiment_receiver = mean(predicted_targeted_sentiment, na.rm = TRUE))

combined_df <- merge(avg_sentiment_sender, avg_sentiment_receiver, by.x = "Sender_id", by.y = "Receiver_id", all = TRUE)

# Initial correlation

cor(combined_df$avg_sentiment_sender,combined_df$avg_sentiment_receiver,use="pairwise.complete.obs")

# Lagged effect of interactions

data3 <- data
data3$Sender_id <- as.numeric(as.character(data3$Sender_id))
data3$Receiver_id <- as.numeric(as.character(data3$Receiver_id))

data3$user_pair <- paste(pmin(data3$Sender_id, data3$Receiver_id), 
                      pmax(data3$Sender_id, data3$Receiver_id), sep = "_")

#NOTE: "tweet_order" is the order of each tweet within each user_pair.
# It was originally created using the raw date for each tweet:
# data <- data %>%
#   arrange(user_pair, date) %>%
#   group_by(user_pair) %>%
#   mutate(tweet_order = row_number()) %>%
#   ungroup()

data3 <- data3 %>% 
  arrange(user_pair, tweet_order) %>%
  group_by(user_pair) %>%
  mutate(sentiment_l1 = lag(predicted_targeted_sentiment,n=1, default = NA),
         sentiment_l2 = lag(predicted_targeted_sentiment,n=2, default = NA),
         sentiment_l3 = lag(predicted_targeted_sentiment,n=3, default = NA),
         sentiment_l4 = lag(predicted_targeted_sentiment,n=4, default = NA),
         sentiment_l5 = lag(predicted_targeted_sentiment,n=5, default = NA))
pair_df <- data3 %>% group_by(user_pair) %>% summarise(n=n())
pair_df$many_interaction <- as.numeric(pair_df$n>20)
data3 <- merge(data3,pair_df,by="user_pair",all.x=T)

m7 <- lm(predicted_targeted_sentiment ~ sentiment_l1, data = data3)
m8 <- lm(predicted_targeted_sentiment ~ sentiment_l1+factor(user_pair), data = data3[data3$many_interaction==1,])
m9 <- lm(predicted_targeted_sentiment ~ sentiment_l1+sentiment_l2+sentiment_l3+sentiment_l4+sentiment_l5+ inparty*sender_gender*receiver_gender+party_id_sender+party_id_receiver+monthyear, data = data3)
m10 <- lm(predicted_targeted_sentiment ~ inparty*sender_gender*receiver_gender+party_id_sender+party_id_receiver+monthyear, data = m9$model)

stargazer(m7,m8,m9,m10,
          omit = c("party_id_receiver", "country", "monthyear","party_id_sender","user_pair"),
          keep.stat = c("n", "rsq", "adj.rsq"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="text",
          report="vc*",
          out="tables_and_figures/tbl5.html")

# Likes and Shares

likes_1 <- lm(likes~factor(predicted_targeted_sentiment),data=data) # NOTE: Requires "likes" variable
shares_1 <- lm(shares~factor(predicted_targeted_sentiment),data=data) # NOTE: Requires "shares" variable

likes_preds <- avg_predictions(likes_1, variables = "predicted_targeted_sentiment") %>%
  mutate(outcome = "Likes")
shares_preds <- avg_predictions(shares_1, variables = "predicted_targeted_sentiment") %>%
  mutate(outcome = "Shares")
reaction_preds <- bind_rows(likes_preds, shares_preds)


png(file="tables_and_figures/fg7_oa.png",
    width=12, height=6, units="cm", res=600)
ggplot(reaction_preds, aes(x = as.factor(predicted_targeted_sentiment), 
                           y = estimate, 
                           ymin = conf.low, 
                           ymax = conf.high)) +
  geom_point() +
  geom_errorbar(width = 0.2) +
  facet_wrap(~ outcome,scales="free") +
  labs(x = "Targeted Sentiment", y = "number of ...") +
  theme_bw()
dev.off()